package servlet.cuota;

import java.io.IOException;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import condominio.excepcion.DAOExcepcion;
import condominio.modelo.Cuota;
import condominio.modelo.Usuario;
import condominio.modelo.Vivienda;
import condominio.negocio.GestionCuotas;
import condominio.negocio.GestionViviendas;


@WebServlet("/CuotaListarViviendas")
public class CuotaListarViviendas extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    
    public CuotaListarViviendas() {
        super();
        // TODO Auto-generated constructor stub
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		HttpSession session = request.getSession();
		Usuario vo = (Usuario)session.getAttribute("USUARIO_ACTUAL");
		
		if (vo ==null){
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
			return;
		}
		
		
		GestionViviendas negocio = new GestionViviendas();
		try {
	
			Collection<Vivienda> lista = negocio.listar();
			// Guardar en el ambiente de request
			request.setAttribute("Viviendas", lista);
			RequestDispatcher rd = request.getRequestDispatcher("CuotasNuevo.jsp");
			rd.forward(request, response);

		} catch (DAOExcepcion e) {
			System.out.println(e.getMessage());
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}

	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		

	}

}
